package com.isxcode.link.template.service;

import com.isxcode.link.common.menu.SyncType;
import com.isxcode.link.common.pojo.LinkRequest;
import com.isxcode.link.common.pojo.LinkResponse;
import com.isxcode.link.common.template.LinkTemplate;
import com.isxcode.link.template.pojo.TemplateReq;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Slf4j
@Service
@RequiredArgsConstructor
public class TemplateService {

    private final LinkTemplate linkTemplate;

    public void execute() {

        // 构建请求对象
        LinkRequest linkRequest = LinkRequest.builder()
            .command("sqoop import " +
                "    -Dorg.apache.sqoop.export.text.dump_data_on_error=true " +
                "    -Dorg.apache.sqoop.splitter.allow_text_splitter=true " +
                "    --verbose " +
                "    --driver com.mysql.cj.jdbc.Driver " +
                "    --connect \"jdbc:mysql://localhost:30102/demo\" " +
                "    --username root " +
                "    --password isxcode123 " +
                "    --query \"select username,age from demo_table where \\$CONDITIONS\" " +
                "    --split-by username " +
                "    --target-dir hdfs://localhost:9000/user/hive/warehouse/demo_table " +
                "    --fields-terminated-by '\\001' " +
                "    --append ")
            .build();

        LinkResponse linkResponse = linkTemplate.build("worker1").execute(linkRequest);
        log.info("调用状态" + linkResponse.toString());
    }

    public void execute2() {

        String jsonConfig = "{" +
            "}";

        LinkRequest linkRequest = LinkRequest.builder().jsonConfig(jsonConfig).build();

        LinkResponse linkResponse = linkTemplate.build().execute(linkRequest);
        log.info("调用状态" + linkResponse.toString());
    }

    public void getLog() {

        LinkRequest linkRequest = LinkRequest.builder()
            .executeId("55da9b1e76534df3a80803bb5c2a1d2e")
            .build();

        LinkResponse linkResponse = linkTemplate.build("worker1").getLog(linkRequest);
        log.info("调用状态" + linkResponse.toString());
    }

}
